package com.arron.algorithm.leetcodetop100.贪心;

/**
 *  构造题
 *  https://leetcode.cn/problems/task-scheduler/solutions/1924711/by-ac_oier-3560/
 */
public class 任务调度器 {


    public int leastInterval(char[] tasks, int n) {


        //找到出现任务数最多的任务
        int[] taskCountArrays = new int[26];
        int max = 0;
        for (int i = 0; i < tasks.length; i++) {
            taskCountArrays[tasks[i]-'A']++;
            max = Math.max(taskCountArrays[tasks[i]-'A'],max);
        }

        //统计等于最大任务数有多少种
        int count = 0;
        for (int i = 0; i < 26; i++) {
            if (taskCountArrays[i] == max){
                count++;
            }
        }

        return Math.max((max-1)*(n+1)+count,tasks.length);
    }

}
